package configs

import (
	_ "embed"
	"github.com/BurntSushi/toml"
	"io/ioutil"
)

// FileConfig
// todo: add validator for the config file
type FileConfig struct {
	GRPC struct {
		// monitor-backend ip address
		BackendAddr string
	}

	Env struct {
		// is working in production mode
		IsProd bool
		// log store path
		Log string
	}

	TLS struct {
		// control whether the gRPC connection is safe
		SafeConnection bool
		ServerName     string
	}

	Auth struct {
		Token string
	}
}

var Config FileConfig

const configLocation = "./config.toml"

func LoadToml() error {
	rawConfig, err := ioutil.ReadFile(configLocation)
	if err != nil {
		return err
	}
	return toml.Unmarshal(rawConfig, &Config)
}
